/*
 * Copyright (c) 2016-2018 Wuhan Ruler Network Company LTD.
 */
package com.jmyd.txlcn.base.result;

import java.util.HashMap;

/**
 * 返回对象工具
 *
 * @author samphin
 * @date 2020-12-30 10:54:10
 */
public final class ResponseUtils {
    private ResponseUtils() {
    }

    /**
     * 返回对象结果
     *
     * @param t
     */
    public static <T> Response<T> returnApiObjectSuccess(T t) {
        if (t == null) {
            return new Response(true, ResponseConstant.SUCCESS.getCode(), ResponseConstant.SUCCESS.getShowMsg(), "", new HashMap<>(1));
        } else {
            return new Response<>(true, ResponseConstant.SUCCESS.getCode(), ResponseConstant.SUCCESS.getShowMsg(), "", t);
        }
    }

    /**
     * 简化消息提示，客户端得到该错误只会直接显示消息内容
     *
     * @param msg
     */
    public static <T> Response<T> returnCommonException(String msg) {
        return new Response<T>(false, ResponseConstant.SYS_EXCEPTION.getCode(), msg, msg, null);
    }

    public static <T> Response<T> returnCommonException(String msg, String code) {
        return new Response<T>(false, code, msg, msg, null);
    }
}
